<HEAD>
<STYLE TYPE="text/css">
	A.cancelled { color: green; text-decoration: underline }
	A.trouble { color: red; text-decoration: underline }
	A.dealerasst { color: #888800; text-decoration: underline }
	A { color: blue; text-decoration: none }
	table { table-layout: fixed; width:800px; }
	td.name { width:300px; }
</STYLE></HEAD>

<?php

require('globals.php');

$result_tables_array = array();
$result_tables_list = array();

$info_grabber_query = "SELECT
	dealership_name, dealer_id, tax_id, trouble, cancelled, dealer_last_name, dealer_first_name, is_notified from " . $dealers_table .
	" WHERE dealer_id != '998' ORDER BY dealership_name asc";
//$table_grabber_query = "SELECT row_a_assignment, row_b_assignment from " . $tables_table;
$table_grabber_query = "select d.dealer_id, t.row_a_assignment, t.row_b_assignment,
						group_concat(t.row_number separator \"/\") from "
						. $dealers_table . " d, " . $tables_table . " t where
						(d.dealer_id = t.row_a_assignment || d.dealer_id = t.row_b_assignment)
						group by d.dealer_id order by d.dealership_name";

if (!($link = mysql_connect($host, $user, $password)))
	die('Could not connect: ' . mysql_error());

if (!(mysql_select_db($database)))
	die('Could not select db ' . $database . ': ' . mysql_error());

$result = mysql_query($info_grabber_query, $link);
$result_tables = mysql_query($table_grabber_query, $link);

while($row = mysql_fetch_array($result_tables)) {
	array_push($result_tables_array,$row[0]);
	array_push($result_tables_array,$row[1]);
	array_push($result_tables_array,$row[2]);
	array_push($result_tables_list,$row[3]);
}

if (!$result || !$result_tables)
	die('Either no matches or the query failed...' . mysql_error());

$range = mysql_num_rows($result);

?><center><TABLE border=1 cellpadding=5 rules=rows><?php
$j = 0;
for ($i=0; $i<$range; $i++) {
	$row = mysql_fetch_row($result);
	?>
	<TR><TD class="name"><A HREF="Display Dealer.php?id=<?=$row[1]?>">
	<?=$row[0]?></A></TD><TD><?=$row[5] . ', ' . $row[6] ?>
	</TD><TD><?php
	if (in_array($row[1], $result_tables_array)) {
		//echo "Assigned";
		echo $result_tables_list[$j++];
	}
	?>
	</TD><TD><?php
	if ($row[7])
		echo "Notified";
	?>
	</TD><TD><?php
	if ($row[3]) {
		?> Problem With Application<?
	}
	if ($row[4]) {
		?> Cancelled <?php
	}
	?>&nbsp;</TD></TR>
	<?php
}

?></TABLE></center>

<center><input type=button value="Back to Front" onclick="location.href = 'http://<?=$LOCAL_IP ?>/';">